package grafica;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class MyLevelPanel extends JPanel implements	MouseMotionListener, MouseListener{
	private Myframe gameFrame;
	private JList listaLivelli;
	private JScrollPane scroll;
	private Color colorButton;
	private Toolkit t;
	
	public MyLevelPanel(Myframe gameFrame){
		this.gameFrame = gameFrame;
		t = Toolkit.getDefaultToolkit();
		colorButton = Color.BLUE;
		listaLivelli = new JList(listaLivelliEditor());
		listaLivelli.setPreferredSize(new Dimension (130,200)); 
		listaLivelli.setSelectedIndex(0);
		scroll = new JScrollPane(listaLivelli);
		scroll.setPreferredSize(new Dimension (150,200));
		JLabel l = new JLabel(new ImageIcon(t.getImage("images/Menu/MegaMenu7.gif")));
		l.setPreferredSize(new Dimension (180,70));
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
		this.add(l);
		this.add(scroll);
		this.setPreferredSize(new Dimension (300,200));
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponents(g);
		g.drawImage(t.getImage("images/Menu/spazio1.gif"),0, 0, null);
		g.drawImage(t.getImage("images/Menu/menuTitle.gif"), 80, 440, null);
		g.setColor(colorButton);
		g.fillRoundRect(90, 310,130, 40, 20, 30);
		g.setFont(gameFrame.getMenu().getMyFont());
		g.setColor(Color.WHITE);
		g.drawString("GIOCA", 110, 340);
	}
	
	private String[] listaLivelliEditor(){
		File f = new File("editor"+File.separator+"levels");
		String liv[]=f.list();
		return liv;
	}
	
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseMoved(MouseEvent e) {
		if((e.getX()> 90)&& (e.getX() < 220)&&(e.getY()< 340) && (e.getY()> 310)){
			colorButton = Color.CYAN;
			this.repaint();
		}
		else{
			colorButton = Color.BLUE;
			this.repaint();
		}
	}

	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent e) {
		if((e.getX()> 90)&& (e.getX() < 220)&&(e.getY()< 340) && (e.getY()> 310)){
			gameFrame.avviaPartita(listaLivelli.getSelectedIndex(), false);
		}
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}
